<?php
$iJob = (array_key_exists('iJob', $_REQUEST) ? $_REQUEST['iJob'] : 0);
if ($iJob == 0) {
	$oJob = new Job();
}
else {
	$oJob = JobHandler::getJob($_REQUEST['iJob']);
}

if (isPosted()) {
	$oJob->fillFromRequest(array(
		'iID' => 'iJob',
		'sName' => 'sName',
		'iJobgroup' => 'iJobgroup'
	));
}

$oJobgroups = JobgroupHandler::getJobgroups();

?>
<div id="layer_job_add" class="hidden" style="visibility: visible;">
<form action="index.php" method="post" name="form_job_add">
<input type="hidden" name="sAction" value="<?php print ($iJob == 0 ? 'job-add' : 'job-change') ?>" />
<input type="hidden" name="iJob" value="<?php print $iJob; ?>" />
<table class="boxborder" cellspacing="0">
	<tr>
		<td class="boxhandle" colspan="2"><?php print msg('New project') ?></td>
	</tr>
	<tr>
		<td class="fieldname"><?php print msg('Name') ?>:</td>
		<td class="fieldvalue">
			<input type="text" size="20" name="sName" value="<?php print $oJob->sName; ?>" />
			<?php ErrorHandler::showFormErrors('sName'); ?>
		</td>
	</tr>
<?php
if (count($oJobgroups) > 0) {
	?>
	<tr>
		<td class="fieldname"><?php print msg('Group') ?>:</td>
		<td class="fieldvalue">
			<select name="iJobgroup">
				<option value="0">[ <?php print msg('None') ?> ]</option>
<?php
foreach ($oJobgroups as $oThisJobgroup)
{
	echo '<option value="'.$oThisJobgroup->iID.'" '.($oThisJobgroup->iID == $oJob->iJobgroup ? 'selected' : '').'>'.$oThisJobgroup->sName.'</option>';
}
?>
			</select>
			<?php ErrorHandler::showFormErrors('iJobgroup'); ?>
		</td>
	</tr>
	<?php
}
?>
	<tr>
		<td class="boxbody" style="text-align: center;" colspan="2">
			<input type="submit" value="<?php print msg('OK') ?>">
			<input type="button" value="<?php print msg('Cancel') ?>" onClick="layerHide('layer_job_add');">
		</td>
	</tr>
</table>
</form>
</div>
